﻿App.Product = function() {

    return {

        currentFormValues: {},

        getTopStore: function() {
            var topStore = new Ext.data.Store({
            	autoLoad:true,
				baseParams:{start:0, limit:10,flag:"huohaofenpei"},//货号分配表示
				proxy: new Ext.data.HttpProxy({
					url : 'product/productlist'
				}),
                remoteSort: false,
                reader: new Ext.data.JsonReader({
					totalProperty : 'totalCount',
					root : 'rows',
					idProperty : 'logistics_id',
					fields: [{
						name: 'logistics_id',
						type: 'string'
					},
					{
						name: 'deal_id',
						allowBlank: false
					},
					{
						name: 'object_id',
						allowBlank: false
					},
					{
						name: "start_name",
						type: 'string'
					},
					{
						name: "end_name",
						type: 'string'
					},
					{
						name: "trucker",
						type: 'string'
					},
					{
						name: "trucker_phone",
						type: 'number'
					},
					{
						name: "truck_nbr",
						type: 'string'
					},
					{
						name: "sign_staff_name",
						type: 'string'
					},
					{
						name: "payout_staff_name",
						type: 'string'
					},
					{
						name: "sign_time",
						type: 'string'
//						dateFormat: 'time'
					},
					{
						name: "payout_time",
						type: 'string'
//						dateFormat: 'time'
					}]
				})
            });
            return topStore;
        },

        getForm: function() {
        	var locationStore = new Ext.data.Store({
            	autoLoad:false,
//				baseParams:{start:0, limit:23},
				proxy: new Ext.data.HttpProxy({
					url : 'localtion/localtionList'
				}),
                remoteSort: false,
                reader: new Ext.data.JsonReader({
					totalProperty : 'totalCount',
					root : 'rows',
					idProperty : 'local_id',
					fields: [{
						name: 'local_id',
						type: 'string'
					},
					{
						name: 'local_name',
						type: 'string'
					}]
				})
            });
        	var truckStore = new Ext.data.Store({
            	autoLoad:false,
//				baseParams:{start:0, limit:23},
				proxy: new Ext.data.HttpProxy({
					url : 'truck/items'
				}),
                remoteSort: false,
                reader: new Ext.data.JsonReader({
					totalProperty : 'totalCount',
					root : 'rows',
					idProperty : 'truck_id',
					fields: [{
						name: 'truck_id',
						type: 'string'
					},
					{
						name: 'truck_nbr',
						type: 'string'
					}]
				})
            });
        	var staffStore = new Ext.data.Store({
            	autoLoad:false,
//				baseParams:{start:0, limit:23},
				proxy: new Ext.data.HttpProxy({
					url : 'user/users'
				}),
                remoteSort: false,
                reader: new Ext.data.JsonReader({
					totalProperty : 'totalCount',
					root : 'rows',
					idProperty : 'staff_id',
					fields: [{
						name: 'staff_id',
						type: 'string'
					},
					{
						name: 'name',
						type: 'string'
					}]
				})
            });
        	var truckerStore = new Ext.data.Store({
            	autoLoad:false,
            	baseParams:{post_id:'2'},//2表示司机
				proxy: new Ext.data.HttpProxy({
					url : 'product/getTrucker'
				}),
                remoteSort: false,
                reader: new Ext.data.JsonReader({
					idProperty : 'staff_id',
					fields: [{
						name: 'staff_id',
						type: 'string'
					},
					{
						name: 'name',
						type: 'string'
					}]
				})
            });
        	var trucker_otherStore = new Ext.data.Store({
            	autoLoad:false,
				proxy: new Ext.data.HttpProxy({
					url : 'user/users'
				}),
                remoteSort: false,
                reader: new Ext.data.JsonReader({
                	totalProperty : 'totalCount',
					root : 'rows',
					idProperty : 'staff_id',
					fields: [{
						name: 'staff_id',
						type: 'string'
					},
					{
						name: 'name',
						type: 'string'
					}]
				})
            });
            var frm = new Ext.form.FormPanel({
            	url:'product/save',
                labelAlign: 'left',
                buttonAlign: 'center',
                bodyStyle: 'padding:5px',
                frame: true,
                labelWidth: 80,
                defaultType: 'textfield',
                defaults: {
                    allowBlank: false,
                    anchor: '90%',
                    enableKeyEvents: true
                },
                items: [
                  {
                    xtype: 'hidden',
                    name: 'logistics_id',
                    value: ''
                },{
                	name:"deal_id",
                	fieldLabel:"单号"
                },{
                	fieldLabel:"司机",
            		xtype:'combo',
            		hiddenName :"trucker",
            		store: truckerStore,
                    displayField:'name',
                    valueField :'staff_id',
                    mode: 'remote',
                    triggerAction: 'all',
                    editable: false,
                    emptyText:'选择司机....',
                    listeners : {
                		expand:function(comb){
                			comb.getStore().reload();
                		}
                	}
                },{
                	fieldLabel:"押车人",
            		xtype:'combo',
            		hiddenName :"trucker_other",
            		store: trucker_otherStore,
                    displayField:'name',
                    valueField :'staff_id',
                    mode: 'remote',
                    triggerAction: 'all',
                    editable: false,
                    emptyText:'选择押车人....',
                    listeners : {
                		expand:function(comb){
                			comb.getStore().reload();
                		}
                	}	
                }/*,{
                	fieldLabel: '发货地',
            		xtype:'combo',
            		hiddenName :"local_start_id",
            		store: locationStore,
                    displayField:'local_name',
                    valueField :'local_id',
                    mode: 'remote',
                    triggerAction: 'all',
                    editable: false,
                    emptyText:'选择地点....',
                    listeners : {
                		expand:function(comb){
                			comb.getStore().reload();
                		}
                	}
                }*/,{
                	fieldLabel: '收货物流部',
            		xtype:'combo',
            		hiddenName :"local_end_id",
            		store: locationStore,
                    displayField:'local_name',
                    valueField :'local_id',
                    typeAhead: true,
                    mode: 'remote',
                    forceSelection: true,
                    editable: false,
                    triggerAction: 'all',
                    emptyText:'选择地点....',
                    selectOnFocus:true,
                    listeners : {
                		expand:function(comb){
                			comb.getStore().reload();
                		}
                	}
                },{
                	fieldLabel: '车辆',
            		xtype:'combo',
            		hiddenName :"truck_id",
            		store: truckStore,
                    displayField:'truck_nbr',
                    valueField :'truck_id',
                    typeAhead: true,
                    editable:false,
                    mode: 'remote',
                    forceSelection: true,
                    triggerAction: 'all',
                    emptyText:'选择车辆....',
                    selectOnFocus:true,
                    listeners : {
                		expand:function(comb){
                			comb.getStore().reload();
                		},
                		focus:function(comb){
                			comb.getStore().reload();
                		}
                	}
                },{
                	fieldLabel: '签收人员',
            		xtype:'combo',
            		hiddenName :"sign_staff_id",
            		store: staffStore,
                    displayField:'name',
                    valueField :'staff_id',
                    typeAhead: true,
                    mode: 'remote',
                    forceSelection: true,
                    triggerAction: 'all',
                    emptyText:'选择签收人员....',
                    selectOnFocus:true,
                    editable: false,
                    listeners : {
                		expand:function(comb){
                			comb.getStore().reload();
                		}
                	}
                },
                {
                    xtype: 'compositefield',
                    fieldLabel: '签收时间',
                    msgTarget : 'side',
                    defaults: {
                        flex: 1
                    },
                    items: [
						{
							xtype:'datefield',
							format:"Y-m-d",
						    name: 'sign_date',
						    value:new Date()
						 },
						 {
	                    	 xtype:'timefield',
	                         name: 'sign_time',
	                         format:'H:i:s',
	                         maxValue: '23:59:59',
	                         minValue: '00:00:00',
	                         value:'9:00'
	                     }
                    ]
                },
              {
                	fieldLabel: '派发人员',
            		xtype:'combo',
            		hiddenName :"payout_staff_id",
            		store: staffStore,
                    displayField:'name',
                    valueField :'staff_id',
                    typeAhead: true,
                    mode: 'remote',
                    forceSelection: true,
                    editable: false,
                    triggerAction: 'all',
                    emptyText:'选择派发人员....',
                    selectOnFocus:true,
                    listeners : {
                		expand:function(comb){
                			comb.getStore().reload();
                		}
                	}
                },{
                    xtype: 'compositefield',
                    fieldLabel: '派发时间',
                    msgTarget : 'side',
                    defaults: {
                        flex: 1
                    },
                    items: [
						{
							xtype:'datefield',
							format:"Y-m-d",
						    name: 'payout_date',
						    value:new Date()
						 },
						 {
	                    	 xtype:'timefield',
	                         name: 'payout_time',
	                         format:'H:i:s',
	                         maxValue: '23:59:59',
	                         minValue: '00:00:00',
	                         value:'9:00'
	                     }
                    ]
                }],
                //items
                buttons: [{
                    text: '保存',
                    scope: this,
                    handler: function() {
                       this.submit();
                    }
                },
                {
                    text: '重置',
                    scope: this,
                    handler: function() {
                        this.frm.form.reset();
                        this.frm.form.setValues(this.currentFormValues);
                        this.frm.form.clearInvalid();
                    }
                }] //buttons
            }); //FormPanel
            return frm;
        },

        submit: function() {
            if (this.frm.form.isValid()) {
				this.frm.getForm().submit({
                    waitTitle: '保存数据',
                    waitMsg: '正在保存……',
                    scope: this,
                    method: 'post',
                    params: '',
                    success: function(resp, opts) {
    					if(opts.result.success=='true') {
    						Ext.Msg.alert('信息', opts.result.info);
    						this.frm.findParentByType('window').hide();
    						Ext.getCmp('topGrid').store.reload();
    						Ext.getCmp('topGrid').getSelectionModel().clearSelections();
    						this.lowerGrid.store.removeAll();
    					}else {
                            Ext.Msg.alert('信息', opts.result.info);
                        }
    				},
    				failure: function(resp,opts) {
    					var result = Ext.util.JSON.decode(resp.responseText);
    					var info = result.info;
    					Ext.Msg.alert('提示', info); 
    				}
                });
            }
        },

        getDialog: function() {
        	return new Ext.Window({
                width: 400,
                height: 300,
                title: '',
                plain: true,
                closable: true,
                resizable: false,
                frame: true,
                layout: 'fit',
                closeAction: 'hide',
                border: false,
                modal: true,
                items: [{html:''}],
                listeners: {
                    scope: this,
                    render: function(fp) {
                        this.frm.form.waitMsgTarget = fp.getEl();
                    },
                    show: function() {
                		this.frm.form.setValues(this.currentFormValues);
                        this.frm.form.clearInvalid();
                    }
                }
            }); //dlg
        },
        highLight: function(value) {
        	var key = App.Product.store.baseParams.query;
        	var v = value ? value.toString() : '';
        	if (Ext.isString(v) & Ext.isString(key)) {
        		if (key.length > 0) {
        			var re = new RegExp(key, "g");
        			return v.replace(re, "<span style='color:red;background-color:yellow;'>" + key + "</span>");
        		} else {
        			return v;
        		}
        	} else {
        		return v;
        	}
        },
        dateformate: function(value) {
        	return value.format("Y-m-d h:i:s");
        },
        createGrid: function(id) {

            var panel = Ext.getCmp(id);

            panel.body.dom.innerHTML = "";
            this.gird = this.getTopGrid();
            this.lowerGrid=this.getLowerGird();
            panel.add(this.gird);
            panel.add(this.lowerGrid);
        },
        getTopGrid: function (){
        	
        	var sm = new Ext.grid.RowSelectionModel({singleSelect:true});
            var topGrid = new Ext.grid.GridPanel({
                tbar: new Ext.PagingToolbar({
                    pageSize: 10,
                    displayInfo: true,
                    store: this.store,
                    items: ['-', 
                            {
                        text: '增加单号',
                        scope: this,
                        handler: function(){
	                    	Ext.apply(this.currentFormValues, {
	                    		logistics_id:'',
                    			deal_id:'',
//                    			local_start_id:'',
                    			local_end_id:'',
                    			truck_id:'',
                    			sign_staff_id:'',
                    			payout_staff_id:'',
                    			sign_time:'',
                    			sign_date:new Date(),
                    			sign_time:'09:00:00',
                    			payout_date:new Date(),
                    			payout_time:'09:00:00'
	                        });
                    		this.add("添加物流单",this.frm, 500, 400);
                    	}
                    },
                    {
                        text: '编辑单号',
                        scope: this,
                        handler: function(){
	                    	if(this.gird.getSelectionModel().hasSelection()){
	                    		var selectdata = this.gird.getSelectionModel().getSelected().data;
		                    	Ext.apply(this.currentFormValues, {
		                    		logistics_id:selectdata.logistics_id,
		                			deal_id:selectdata.deal_id,
//		                			local_start_id:'',
		                			local_end_id:'',
		                			truck_id:'',
		                			sign_staff_id:'',
		                			payout_staff_id:'',
		                			sign_date:selectdata.sign_time.split(" ")[0],
		                			sign_time:selectdata.sign_time.split(" ")[1],
		                			payout_date:selectdata.payout_time.split(" ")[0],
		                			payout_time:selectdata.payout_time.split(" ")[1]
		                       });
		                    	this.edit("编辑单号",this.frm, 500, 400);
	                		}else{
	                			Ext.Msg.alert('提示','请选择单号');
	                		}
                    	}
                    },
                    {
                        text: '删除单号',
                        scope: this,
                        handler: function(){
	                		this.del(this.gird,"product/deletelogobjbylogid");
	                		this.lowerGrid.store.removeAll();
	                }
                    },
                    '-', new Ext.ux.form.SearchField({
                        store: this.store,
                        width: 110
                    }),"-",{
                    	 text: '<b style="font-size:12px;"><font color=red>发车</font></b>',
                         scope: this,
                         handler: function(){
                    		this.setLogisStart();
                    	}
                    }]
                }),
                title:"单号管理",//打印必须设置tile
                plugins: [Ext.ux.plugins.Print],//打印按钮
                loadMask: true,
                autoHeight:true,
                viewConfig : {autoFill:false,forceFit:true},
                id:'topGrid',
//                anchor:'top 50%',
                store: this.store,
                sm: sm,
                columns: [new Ext.grid.RowNumberer(),{
                    header: "单号",
                    sortable: true,
                    dataIndex: 'deal_id'
                },
                {
                    header: "起始地点",
                    sortable: true,
                    dataIndex: 'start_name'
//                    renderer: this.highLight(value,this.store)
                },
                {
                	header: "目的地点",
//                	width: 300,
                	sortable: true,
                	dataIndex: 'end_name'
//                	renderer: this.highLight(value,this.store)
                },
                {
                    header: "司机",
                    sortable: true,
                    dataIndex: 'trucker',
                    align: 'right'
                },
                {
                	header: "司机电话",
                	sortable: true,
                	dataIndex: 'trucker_phone',
                	align: 'right'
                },
                {
                    header: "车辆信息",
                    sortable: true,
                    dataIndex: 'truck_nbr',
                    align: 'right'
                },
                {
                	header: "签收人员",
                	sortable: true,
                	dataIndex: 'sign_staff_name'
//                	renderer: this.highLight(value,this.store)
                },
                {
                	header: "派发人员",
//                	width: 300,
                	sortable: true,
                	dataIndex: 'payout_staff_name'
//                	renderer: this.highLight(value,this.store)
                },
                {
                	header: "签收时间",
                	width: 130,
                	sortable: true,
                	dataIndex: 'sign_time'
//                	renderer: this.dateformate
                },
                {
                	header: "派发时间",
                	width: 130,
                	sortable: true,
                	dataIndex: 'payout_time'
//                	renderer: this.dateformate
                }],
                listeners: {
                    scope: this,
                    rowclick: function(grid,index) {
            			if(grid.getSelectionModel().hasSelection()){
	            			var logistics_id = grid.getSelectionModel().getSelected().data.logistics_id;
	            			this.lowerGrid.store.baseParams={start:0, limit:12,'logistics_id':logistics_id};
	            			this.lowerGrid.store.load();
            			}else{
            				this.lowerGrid.store.removeAll();
            			}
            		}
                }
            });
            return topGrid;
        },
        getLowerGird: function(){
        	var lowerStore = new Ext.data.Store({
                autoLoad:false,
				baseParams : {start:0, limit:12,stop:'fangzhishuaxin'},
				proxy: new Ext.data.HttpProxy({
					url : 'inhouse/items'
				}),
                remoteSort: false,
				reader: new Ext.data.JsonReader({
					totalProperty : 'totalCount',
					root : 'rows',
					idProperty : 'object_id',
					fields: [{
						name: 'object_id',
						type: 'string'
					},{
						name: 'objid',
						type: 'string'
					},{
						name:'obj_num',
						type:'number'
					},{
						name:'obj_name'
					},
					{
						name: 'from_addr',
						allowBlank: false
					},
					{
						name: 'to_addr',
						allowBlank: false
					},
					{
						name: 'from_name',
						allowBlank: false
					},
					{
						name: 'to_name',
						allowBlank: false
					},
					{
						name:'from_tell'
					},
					{
						name: "to_tell"
					},
					{
						name:"cost_type"
					},
					{
						name: "traff_fee"
					},
					{
						name: "mid_fee"
					},
					{
						name: "saf_fee"
					},
					{
						name: "oth_fee"
					},
					{
						name: "sum_fee",
						type:'double'
					},
					{
						name: "pre_fee"
					},
					{
						name: "inst_fee"
					},
					{
						name:"brief"
					},
					{
						name: "op_time",
						type: 'date',
						dateFormat: 'time'
					}]
				})
            });
        	var sm = new Ext.grid.CheckboxSelectionModel();
            var lowerGird = new Ext.grid.GridPanel({
            	autoHeight:true,
                loadMask: true,
                width:"120%",
                ref:"../lowerGird",
                tbar: new Ext.PagingToolbar({ 
                	pageSize: 12 ,//分页必须加的参数.最好和store里面的limit保持一致
                	displayInfo: true,
                    store: lowerStore,
                    items:[
                    {
	                    text: '添加货号',
	                    scope: this,
	                    handler: function(){
                    		if(this.gird.getSelectionModel().getCount()!=1){
                    			Ext.Msg.alert('信息', '请选择一个单号!');
                    			return;
                    		}
                    		var grid = this.getLowerGird();
                    		grid.getTopToolbar().remove(11);//移除'增加货物'按钮
                    		grid.getTopToolbar().remove(11);//移除'删除'按钮
                    		grid.getTopToolbar().remove(11);//移除'编辑'按钮
                    		grid.setTitle('');
                    		var logistics_id = this.gird.getSelectionModel().getSelected().id;//物流单号
                    		var button = {
                                text: '保存',
                                scope: this,
                                handler: function(btn){
                					if(btn.findParentByType('grid').getSelectionModel().hasSelection()){
                    					var selects = btn.findParentByType('grid').getSelectionModel().getSelections();
                    					var ids =[];//获取勾选的货物号
                    					for(var i=0;i<selects.length;i++){
                    						ids.push(selects[i].id);//货物号
                    					}
                    					this.save(ids.toString(),logistics_id,btn.findParentByType('grid'),this.lowerGrid);
                    				}else{
                    					 Ext.Msg.alert('信息', '请先选择!');
                    				}
                				}
                              };
                    		grid.buttonAlign='center';
                    		grid.addButton(button);
                    		grid.store.baseParams={start:0, limit:18,'logistics_id':logistics_id,'notin':"notin","logistics_id":logistics_id};
                    		grid.store.load();
                    		this.add("添加货号",grid,0,0);
                    }
	                },
	                {
	                    text: '删除',
	                    scope: this,
	                    handler: function(){
	                		this.del(this.lowerGrid,"product/deletelogobj");
	                }
                },'-', new Ext.ux.form.SearchField({
                    store: lowerStore,
                    width: 110
                })]}),
                title:"货号",//打印必须设置tile
                plugins: [Ext.ux.plugins.Print],//打印按钮
                viewConfig : {autoFill:false,forceFit:true},
                store: lowerStore,
                sm: sm,
                columns: [sm, new Ext.grid.RowNumberer(),
                  {
                    header: "货号",
                    width: 250,
                    sortable: true,
                    dataIndex: 'objid'
//                    renderer: this.highLight
                },
                {
                    header: "货名",
                    width: 250,
                    sortable: true,
                    dataIndex: 'obj_name'
//                    renderer: this.highLight
                },
                {
                    header: "件数",
                    width: 120,
                    sortable: true,
                    dataIndex: 'obj_num'
//                    renderer: this.highLight
                },
                {
                    header: "收货地",
                    width: 250,
                    sortable: true,
                    dataIndex: 'to_addr'
//                    renderer: this.highLight
                },
                {
                    header: "收货人",
                    width: 250,
                    sortable: true,
                    dataIndex: 'to_name'
//                    renderer: this.highLight
                },
                {
                    header: "收货人电话",
                    width: 250,
                    sortable: true
//                    dataIndex: 'to_tell'
                },
                {
                    header: "发货地",
                    width: 200,
                    sortable: true,
                    dataIndex: 'from_addr'
//                    renderer: this.highLight
                },
                {
                    header: "发货人电话",
                    width: 250,
                    sortable: true,
                    dataIndex: 'from_tell'
                },
                {
                    header: "付款方式",
                    width: 250,
                    sortable: true,
                    dataIndex: 'cost_type'
                },
                {
                    header: "运费",
                    width: 180,
                    sortable: true,
                    dataIndex: 'traff_fee'
                },
                {
                    header: "保险费",
                    width: 180,
                    sortable: true,
                    dataIndex: 'saf_fee'
                },
                {
                    header: "中间费",
                    width: 180,
                    sortable: true,
                    dataIndex: 'mid_fee'
                },
                {
                    header: "其它费",
                    width: 180,
                    sortable: true,
                    dataIndex: 'oth_fee'
                },
                {
                    header: "代收费",
                    width: 180,
                    sortable: true,
                    dataIndex: 'inst_fee'
                },
                {
                    header: "垫付费",
                    width: 180,
                    sortable: true,
                    dataIndex: 'pre_fee'
                },
                {
                    header: "汇总",
                    width: 180,
                    sortable: true,
                    dataIndex: 'sum_fee'
                },
       /*         {
                    header: "入库时间",
                    width: 250,
                    sortable: true,
                    dataIndex: 'op_time',
                    renderer: Ext.util.Format.dateRenderer('Y-m-d H:i:s')
                },
             */  {
                    header: "备注",
                    width: 400,
                    sortable: true,
                    dataIndex: 'brief'
                }],
                listeners :{
                	beforerender : function(){
                		this.getStore().on('load',function(store){
                			var obj_num=0;//货物总件数
                			var sum_fee=0;//货物总价钱
                			store.each(function(record){
                				obj_num += record.get('obj_num');
                				sum_fee += record.get('sum_fee');
                			});
                			var date=new Date();
                			var trucker='';
                			var trucker_phone='';
                			var idtentid='';
                			var trucker_other_staff_name='';
                			var newTitle = '';
                			if(this.previousSibling()){
                				trucker = this.previousSibling().getSelectionModel().getSelected().get('trucker')==null?'':this.previousSibling().getSelectionModel().getSelected().get('trucker');
                				trucker_phone = this.previousSibling().getSelectionModel().getSelected().get('trucker_phone')==null?'':this.previousSibling().getSelectionModel().getSelected().get('trucker_phone');
                				idtentid = this.previousSibling().getSelectionModel().getSelected().json.idtentid==null?'':this.previousSibling().getSelectionModel().getSelected().json.idtentid;
                				trucker_other_staff_name = this.previousSibling().getSelectionModel().getSelected().json.trucker_other_staff_name==null?'':this.previousSibling().getSelectionModel().getSelected().json.trucker_other_staff_name;
                				newTitle = "物件"+"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;总件数:"+obj_num+"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;价钱总额:"+sum_fee
			                				+"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;司机:"+trucker+"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;司机电话:"+trucker_phone
			                				+"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;司机身份证:"+idtentid+"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;押车人:"+trucker_other_staff_name
			                				+"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;时间:"+date.getFullYear()+"年"+date.getMonth()+"月"+date.getDate()+"日";
                			}
                			this.setTitle(newTitle);
                		},this);
                	}
                }
            });
            return lowerGird;
        },
        save:function(ids,logistics_id,wingrid,lowergrid ){
        	Ext.Ajax.request({
				method:'post',
				url:"product/savelogobj",
				params:{
					ids:ids,
					logistics_id:logistics_id
				},
				success: function(resp, opts) {
					var result = Ext.util.JSON.decode(resp.responseText);
					var info = result.info;
					if(result.success=='true') {
						Ext.Msg.alert('信息', info);
						wingrid.store.reload();//刷新弹出窗口数据
						//lowergrid.store.reload();//刷新lowergrid(在955行添加了刷新事件)
					}else {
                        Ext.Msg.alert('信息', info);
                    }
				},
				failure: function(resp,opts) {
					var result = Ext.util.JSON.decode(resp.responseText);
					var info = result.info;
					Ext.Msg.alert('提示', info); 
				}
			});
        },
        
        setLogisStart: function(){
        	 if (this.gird.getSelectionModel().hasSelection()) {
        		 var rec = this.gird.getSelectionModel().getSelected();
        		 Ext.Msg.confirm('发车', '确定发车吗？发车后只有收货物流部的人才可见.',
        	                function(btn) {
        	                    if (btn == 'yes') {
        							Ext.Ajax.request({
        								method:'post',
        								url:"product/startcar",
        								params:{
        								logistics_id:rec.data.logistics_id
        								},
        								success: function(resp, opts) {
        									var result = Ext.util.JSON.decode(resp.responseText);
        									var info = result.info;
        									if(result.success==true) {
        										Ext.Msg.alert('信息', info);
        										Ext.getCmp('topGrid').store.reload();
        			    						Ext.getCmp('topGrid').getSelectionModel().clearSelections();
        			    						Ext.getCmp('topGrid').nextSibling().getStore().removeAll();
        									}else {
        	                                    Ext.Msg.alert('信息', info);
        	                                }
        								},
        								failure: function(resp,opts) {
        									var result = Ext.util.JSON.decode(resp.responseText);
        									var info = result.info;
        									Ext.Msg.alert('提示', info); 
        								}
        							});
        	                    }
        	                });
        	 }else{
    		   Ext.Msg.alert('信息', '请选择发车的单号！');
        	 }
        },
        add: function(tile,cmp,width,height) {
        	var dlgadd = this.getDialog();
        	dlgadd.removeAll(true);
        	dlgadd.setTitle(tile);
        	if(width==0 && height==0){//window高宽为零时,默认最大化
        		dlgadd.maximized=true;
        		dlgadd.on("hide", function(){
                	this.lowerGrid.store.reload();
                },this);
        	}
        	dlgadd.setSize(width,height);
        	dlgadd.add(cmp);
        	dlgadd.show();
        },

        edit: function(tile,cmp,width,height) {
        	this.add(tile, cmp, width, height);
        },

        del: function(grid,url) {
            if (grid.getSelectionModel().hasSelection()) {
                var recs = grid.getSelectionModel().getSelections();
                var ids = [];
                for(var i = 0; i < recs.length; i++) {
                    ids.push(recs[i].id);
                }
                Ext.Msg.confirm('删除', '确定删除吗？',
                function(btn) {
                    if (btn == 'yes') {
						Ext.Ajax.request({
							method:'post',
							url:url,
							params:{
								ids:ids.toString()
							},
							success: function(resp, opts) {
								var result = Ext.util.JSON.decode(resp.responseText);
								var info = result.info;
								if(result.success=='true') {
									Ext.Msg.alert('信息', info);
									grid.store.reload();
								}else {
                                    Ext.Msg.alert('信息', info);
                                }
							},
							failure: function(resp,opts) {
								var result = Ext.util.JSON.decode(resp.responseText);
								var info = result.info;
								Ext.Msg.alert('提示', info); 
							}
						});
                    }
                });
            } else {
                Ext.Msg.alert('信息', '请选择！');
            }
        },

        render: function(id) {
            if (!this.store) {
                this.store = this.getTopStore();
            }; //if(!this.store)
            if (!this.frm) {
                this.frm = this.getForm();
            }; //if(!this.frm)

//            if (!this.dlg) {
//                this.dlg = this.();
//            }; //if(!this.dlg)
            this.createGrid(id);
        }

    }; //return
} (); //function
